// 邀请信息管理
<template>
   <div class="search">
     <Row>
        <Card>
          <Row class="operation">
            <Button @click="getDataList" icon="md-refresh">刷新</Button>
          </Row>
          <Modal title="查看大图" v-model="visible" class-name="fl-image-modal">
            <img :src="imgUrl" v-if="visible" style="width: 100%">
          </Modal>

          <Row>
            <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort"></Table>
          </Row>

          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
          </Row>
        </Card>
     </Row>

     <Modal :title="modalTitle" v-model="modalVisible" :mask-closable='false' :width="600">
      <Form ref="form" :model="form" :label-width="100" :rules="formValidate" >
        <FormItem label="是否同意" prop="agree">
          <Select v-model="form.agree" style="width: 100%">
            <Option value="YES">同意</Option>
            <Option value="NO">拒绝</Option>
          </Select>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="modalVisible=false">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="handleSubmit">提交</Button>
      </div>
    </Modal>
   </div> 
</template>

<script>
export default {
  data(){
    return{ 
      submitLoading: false,
      visible:false,
      modalVisible: false,
      total:0,
      modalTitle: "",
      loading: true, // 表单加载状态
      data:[],//表单数据
      searchForm:{
        pageSize:10,
        pageNumber:1,
      },
      form: {
        id: "",
        agree: "",
      },
      formValidate: {
        agree: [{ required: true, message: "请选择是否同意", trigger: "change" }],
      },
      columns: [
      // 表头
      {
        type: "index",
        width: 60,
        align: "center"
      },
      {
        title: "邀请人头像",
        key: "avatar",
        minWidth: 120,
        sortable: false,
        render: (h,params) => {
          return h("avatar",{
            props: {
                src: params.row.avatar
            },
            on: {
                click: ()=> {
                    this.handleView(params.row.avatar)
                }
            }
          })
        }
      },
      {
        title: "邀请人名称",
        key: "nickName",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "邀请人手机号",
        key: "mobile",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "工作室id",
        key: "studioId",
        minWidth: 120,
        sortable: false,
      },
      {
          title: "操作",
          width: 260,
          align: "center",
          fixed: "right",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.remove(params.row);
                    }
                  }
                },
                "删除"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "info",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px",
                  },
                  on: {
                    click: () => {
                      this.dealInvitation(params.row);
                    }
                  }
                },
                "处理邀请"
              ),
            ]);
          }
        }
      ],
      }
    },
    methods:{
      init(){
        this.getDataList()
      },
      handleView(url) {
        this.imgUrl = url;
        this.visible = true;
      },
      getDataList(){
        this.loading = true;
        this.postRequest("/inviteMessage/getInviteMessageList",this.searchForm).then(res =>{
          this.loading = false
          if(res.success){
            var arr = res.result.dataResult;
            for(let val of arr){
              for(let i in val){
                (val[i] === null) ? (val[i] = "-") : ""
              }
            }
            this.data = res.result.dataResult;
            this.total = res.result.currentPageNum;
          } else {
            this.data = [];
            this.total = 0;
          }
        })
      },
      //搜索查询
      handleSearch(){
        this.searchForm.pageNumber = 1;
        this.getDataList()
      },
      changeSort(e) {
        this.searchForm.sort = e.key;
        this.searchForm.order = e.order;
        if (e.order === "normal") {
          this.searchForm.order = "";
        }
        this.getDataList();
      },
      changePage(v) {
        this.searchForm.pageNumber = v;
        this.getDataList();
      },
      changePageSize(v) {
        this.searchForm.pageSize = v;
        this.getDataList();
      },
      clearSelectAll(){
        this.$refs.searchForm.resetFields()
        this.getDataList()
      },
      // 处理邀请
      dealInvitation (v) {
        this.modalTitle = "处理邀请";
        this.$refs.form.resetFields();
        this.form.id = v.studioId;
        this.modalVisible = true;
      },
      handleSubmit () {
        this.$refs.form.validate(valid=> {
          if (valid) {
            this.submitLoading = true;
            this.postRequest("/studio/resolveInvite",this.form).then(res=> {
              this.submitLoading = false
              if (res.success) {
                this.$Message.success("操作成功");
                this.getDataList();
                this.modalVisible = false;
              } else {
                this.$Message.success(res.message);
                this.getDataList();
                this.modalVisible = false;
              }
            })
          }
        })
      },
      // 订单详情 
      remove (v) {
        this.$Modal.confirm({
          title: "删除",
          content: "确定要删除所选数据吗？",
          loading: false,
          onOk: ()=> {
            var data = {
              ids: v.id
            }
            this.postRequest("/inviteMessage/removeInviteMessage", data).then(res=> {
              if (res.success) {
                this.$Message.success("删除成功");
                this.$Modal.remove();
                this.getDataList();
              } else {
                this.$Message.success(res.message);
                this.$Modal.remove();
                this.getDataList();
              }
            })
          }
        })
      }
    },
    mounted(){
      this.init()
    }
}
</script>

<style lang="less">
.search {
    .operation {
        margin-bottom: 2vh;
    }
    .select-count {
        font-size: 13px;
        font-weight: 600;  
        color: #40a9ff;
    }
    .select-clear {
        margin-left: 10px;
    }
    .page {
        margin-top: 2vh;
    }
    .drop-down {
        font-size: 13px;
        margin-left: 5px;
    }
}
</style>